<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
	
	<!-- title -->
	
	<title>
	
		07.Kafka环境搭建 | 
	 
	对线面试官
	</title>
	
	<!-- keywords,description -->
	 
		<meta name="description" content="Java一线大厂面试" />
	

	<!-- favicon -->
	
	<link rel="shortcut icon" href="/luffy/favicon.ico">
	


	<!-- search -->
	<script>
		var searchEngine = "https://www.baidu.com/s?wd=";
		if(typeof searchEngine == "undefined" || searchEngine == null || searchEngine == ""){
			searchEngine = "https://www.google.com/search?q=";
		}
		var homeHost = "";
		if(typeof homeHost == "undefined" || homeHost == null || homeHost == ""){
			homeHost = window.location.host;
		}
	</script>


	
<link rel="stylesheet" href="/luffy/css/main.css">

	
<link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css">

	
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.17.1/build/styles/darcula.min.css">

	
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css">


	
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>

	
<script src="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>

	
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.17.1/build/highlight.min.js"></script>

	
<script src="https://cdn.jsdelivr.net/npm/jquery-pjax@2.0.1/jquery.pjax.min.js"></script>

	
<script src="/luffy/js/main.js"></script>

	
		
<script src="https://cdn.jsdelivr.net/npm/leancloud-storage/dist/av-min.js"></script>

		
<script src="https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js"></script>

	
	
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
	<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3efe99c287df5a1d6f0d02d187e403c1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

<header id="header">
    <a id="title" target="_blank" rel="noopener" href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzU4NzA3MTc5Mg==&action=getalbum&album_id=1657204970858872832&scene=126#wechat_redirect" class="logo">对线面试官</a>

	<ul id="menu">
		
	

	

		<li class="menu-item">
			<a href="https://gitee.com/zhongfucheng/Java3y" class="menu-item-link" target="_blank">
				【戳这里】获取更多原创干货💪💪
			</a>
		</li>
		<li class="menu-item">
			<a href="https://gitee.com/zhongfucheng/Java3y" class="menu-item-link" target="_blank">
				<i class="fa fa-github fa-2x"></i>
			</a>
		</li>
	</ul>
</header>

	
<div id="sidebar">
	<button id="sidebar-toggle" class="toggle" ><i class="fa fa-arrow-right " aria-hidden="true"></i></button>
	
	<div id="site-toc">
		<input id="search-input" class="search-input" type="search" placeholder="按回车全站搜索">
		<div id="tree">
			

			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										00-面试前准备
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/10/30/00-%E9%9D%A2%E8%AF%95%E5%89%8D%E5%87%86%E5%A4%87/01.%E7%AE%80%E5%8E%86/">
										01.简历
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										01-Java基础
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/01-Java%E5%9F%BA%E7%A1%80/01.%20%E6%B3%A8%E8%A7%A3/">
										01. 注解
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/01-Java%E5%9F%BA%E7%A1%80/02.%20%E6%B3%9B%E5%9E%8B/">
										02. 泛型
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/01-Java%E5%9F%BA%E7%A1%80/03.%20JavaNIO/">
										03. JavaNIO
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/01-Java%E5%9F%BA%E7%A1%80/04.%20%E5%8F%8D%E5%B0%84%E5%92%8C%E5%8A%A8%E6%80%81%E4%BB%A3%E7%90%86/">
										04. 反射和动态代理
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										02-Java并发
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/01.%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%9F%BA%E7%A1%80/">
										01. 多线程基础
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/02.%20CAS/">
										02. CAS
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/03.%20synchronized/">
										03. synchronized
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/04.%20AQS%E5%92%8CReentrantLock/">
										04. AQS和ReentrantLock
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/05.%20%E7%BA%BF%E7%A8%8B%E6%B1%A0/">
										05. 线程池
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/06.%20ThreadLocal/">
										06. ThreadLocal
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/07.%20CountDownLatch%E5%92%8CCyclicBarrier/">
										07. CountDownLatch和CyclicBarrier
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/08.%20%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81Java%E5%86%85%E5%AD%98%E6%A8%A1%E5%9E%8B/">
										08. 为什么需要Java内存模型
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/09.%20%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BAJava%E5%86%85%E5%AD%98%E6%A8%A1%E5%9E%8B/">
										09. 深入浅出Java内存模型
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										03-Java容器
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/03-Java%E5%AE%B9%E5%99%A8/01.%20List%E9%9B%86%E5%90%88/">
										01. List集合
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/03-Java%E5%AE%B9%E5%99%A8/02.%20Map%E9%9B%86%E5%90%88/">
										02. Map集合
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										04-Java虚拟机
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/01.%20Java%E7%BC%96%E8%AF%91%E5%88%B0%E6%89%A7%E8%A1%8C%E7%9A%84%E8%BF%87%E7%A8%8B/">
										01. Java编译到执行的过程
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/02.%20%E5%8F%8C%E4%BA%B2%E5%A7%94%E6%B4%BE%E6%9C%BA%E5%88%B6/">
										02. 双亲委派机制
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/03.%20JVM%E5%86%85%E5%AD%98%E7%BB%93%E6%9E%84/">
										03. JVM内存结构
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/04.%20%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6%E6%9C%BA%E5%88%B6/">
										04. 垃圾回收机制
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/05.%20CMS%E5%9E%83%E5%9C%BE%E6%94%B6%E9%9B%86%E5%99%A8/">
										05. CMS垃圾收集器
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/06.%20G1%E5%9E%83%E5%9C%BE%E6%94%B6%E9%9B%86%E5%99%A8/">
										06. G1垃圾收集器
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/24/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/07.%20JVM%E8%B0%83%E4%BC%98/">
										07. JVM调优
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										05-Spring
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/05-Spring/01.%20SpringMVC/">
										01. SpringMVC
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/05-Spring/02.%20Spring%E5%9F%BA%E7%A1%80/">
										02. Spring基础
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/05-Spring/03.%20SpringBean%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F/">
										03. SpringBean生命周期
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										06-Redis
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/06-Redis/01.%20Redis%E5%9F%BA%E7%A1%80/">
										01. Redis基础
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/06-Redis/02.%20Redis%E6%8C%81%E4%B9%85%E5%8C%96/">
										02. Redis持久化
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/06-Redis/03.%20Redis%E4%B8%BB%E4%BB%8E%E6%9E%B6%E6%9E%84/">
										03. Redis主从架构
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/06-Redis/04.%20Redis%E5%88%86%E7%89%87%E9%9B%86%E7%BE%A4/">
										04. Redis分片集群
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										07-消息队列
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/07-%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97/01.%20Kafka%E5%9F%BA%E7%A1%80/">
										01. Kafka基础
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/07-%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97/02.%20%E4%BD%BF%E7%94%A8Kafka%E4%BC%9A%E8%80%83%E8%99%91%E4%BB%80%E4%B9%88%E9%97%AE%E9%A2%98/">
										02. 使用Kafka会考虑什么问题
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										08-MySQL
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/08-MySQL/01.%20MySQL%E7%B4%A2%E5%BC%95/">
										01. MySQL索引
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/08-MySQL/02.%20MySQL%E4%BA%8B%E5%8A%A1%E5%92%8C%E9%94%81%E6%9C%BA%E5%88%B6%E5%92%8CMVCC/">
										02. MySQL事务和锁机制和MVCC
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/08-MySQL/03.%20MySQL%E8%B0%83%E4%BC%98/">
										03. MySQL调优
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										09-项目场景类
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/09-%E9%A1%B9%E7%9B%AE%E5%9C%BA%E6%99%AF%E7%B1%BB/01.%20%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%8E%BB%E9%87%8D%E5%92%8C%E5%B9%82%E7%AD%89/">
										01. 如何实现去重和幂等
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/09-%E9%A1%B9%E7%9B%AE%E5%9C%BA%E6%99%AF%E7%B1%BB/02.%20%E7%B3%BB%E7%BB%9F%E9%9C%80%E6%B1%82%E5%A4%9A%E5%8F%98%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1/">
										02. 系统需求多变如何设计
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/09-%E9%A1%B9%E7%9B%AE%E5%9C%BA%E6%99%AF%E7%B1%BB/03.%20%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">
										03. 设计模式
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										10-计算机网络
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/25/10-%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/01.%20HTTP/">
										01. HTTP
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/10/13/10-%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/02.TCP%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B%E5%92%8C%E5%9B%9B%E6%AC%A1%E6%8C%A5%E6%89%8B/">
										02.TCP三次握手和四次挥手
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										11-算法
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/09/01/11-%E7%AE%97%E6%B3%95/01.%20%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95/">
										01. 排序算法
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/09/02/11-%E7%AE%97%E6%B3%95/02.%20LeetCode%20Easy/">
										02. LeetCode Easy
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/09/02/11-%E7%AE%97%E6%B3%95/02.%20LeetCode%20Medium/">
										02. LeetCode Medium
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										12-austin项目
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/11/01/12-austin%E9%A1%B9%E7%9B%AE/00.%E9%A1%B9%E7%9B%AE%E4%BB%8B%E7%BB%8D/">
										00.项目介绍
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/10/30/12-austin%E9%A1%B9%E7%9B%AE/01.%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">
										01.环境搭建
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/10/30/12-austin%E9%A1%B9%E7%9B%AE/02.%E6%97%A5%E5%BF%97/">
										02.日志
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/11/24/12-austin%E9%A1%B9%E7%9B%AE/03.%E5%B7%A5%E5%85%B7%E5%8C%85/">
										03.工具包
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/11/24/12-austin%E9%A1%B9%E7%9B%AE/04.%E4%BB%8E%E4%B8%80%E6%9D%A1%E7%9F%AD%E4%BF%A1%E5%BC%80%E5%A7%8B/">
										04.从一条短信开始
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/11/24/12-austin%E9%A1%B9%E7%9B%AE/05.%E9%80%89%E6%8B%A9%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8C%E6%8A%80%E6%9C%AF%E9%80%89%E5%9E%8B/">
										05.选择数据库和技术选型
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/11/24/12-austin%E9%A1%B9%E7%9B%AE/06.MySQL%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">
										06.MySQL环境搭建
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file active">
									<a href="/luffy/2021/11/24/12-austin%E9%A1%B9%E7%9B%AE/07.Kafka%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">
										07.Kafka环境搭建
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
		</div>
	</div>
</div>

	<!-- 引入正文 -->
	<div id="content">
		<h1 id="article-title">

	07.Kafka环境搭建
</h1>
<div class="article-meta">
	
	<span>3y</span>
	<span>2021-11-24 08:37:58</span>
		<div id="article-categories">
    
		<span>Categories：</span>
            
    

    
		<span>Tags：</span>
            
    
		</div>

</div>

<div id="article-content">
	<p>大家好，我是3y</p>
<p>今天更新下austin的番外篇#02</p>
<p>前几天在朋友圈和群吐槽了下：“我搭Kafka一个晚上都还没成功”。有好多同学都发出了自己亲生经历的教程给我（甚至在发送之前还主动验证了下该内容有没有问题），我依靠着这么多教程也顺利搭出来了。（<strong>十分感谢这些大佬</strong>）</p>
<p>之前刚建项目的时候有很多同学都说要跟着我一起做austin，我嘴上没答应。但是真正直接过来提<code>pull request</code>的，我是没办法拒绝的（只要你的代码是合理的，对项目整个结构或流程是有帮助，<strong>我是非常欢迎的</strong>)</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gwlnypb3vnj31x80jadj6.jpg"></p>
<p>这个项目的初衷一方面是能够成为Java小白的项目，另一方面是我也能从中学到东西。每个人都有自己熟悉的领域，我对很多东西可能都是不了解或者说是片面的（<strong>不要以为我写文章多了，我就啥都懂，这是不可能的</strong>）</p>
<p>上周有个在评论区讨论得挺多的问题：<strong>MySQL数据库中创建时间/更新时间字段为什么用int类型？</strong></p>
<p>当我被问到，我在建表的时候为什么用int，而不是datetime或者timestamp这种MySQL提供的日期字段类型呢？我当时的第一反应是：“存储时间戳进去不是很正常吗？我一直都这样干的”</p>
<p>于是我抱着好奇的心态问了一遍相关留言的大佬，用datetime有什么好处，总结大概两点吧：</p>
<ol>
<li>在数据库上看时间<strong>直观</strong>（不需要转义）</li>
<li>可以自动更新（updated字段可以不由程序员控制，当更新记录时，框架自动更新该自动）</li>
</ol>
<p>至于int和datetime的<strong>存储大小和处理速度</strong>其实并不在我的考虑范围内，但最终还是没能让我将int改成datetime。</p>
<p>一方面，我在以前的公司几乎所有的表都是int类型（我用习惯了，我承认了，我是懒惰的），另一方面我认为<strong>int是最通用</strong>的（跨平台，跨数据库，跨语言，<strong>也不需要管时区什么的</strong>）。</p>
<p>每个应用程序下都会有对应的TimeUtils工具类，获取一个时间戳和格式化一个时间戳对于程序而言就只是调用一个方法，用得也不糟心。而提出最主要的<strong>直观</strong>，这个确实会带来好处，但按照<strong>我以往的工作经历上</strong>貌似也好像不会提高很多效率。</p>
<p>如果有更好的观点，欢迎在评论区继续留言探讨，并且我希望：<strong>提出疑问或者反对的同时，最好能说明理由</strong>（这样会提高我们交流的效率）。</p>
<h2 id="00、搭建Kafka环境"><a href="#00、搭建Kafka环境" class="headerlink" title="00、搭建Kafka环境"></a>00、搭建Kafka环境</h2><p>下周要在austin项目下引入kafka组件了，今天也来记录下搭建kafka的过程，好让跟着做项目的同学可以快速搭建起来。了解过Kafka的同学可能就知道，Kafka还得依赖Zookeeper组件，这要是在原生的环境下搭建Kafka和Zookeeper还是比较麻烦的。</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gwlmpuxc9gj31780n0acr.jpg"></p>
<p>我个人是不喜欢把时间耗费在搭建环境上的，所以就直接上Docker/Docker Compose吧。</p>
<p>环境：<code>CentOS 7.6 64bit</code></p>
<h2 id="01、Docker环境"><a href="#01、Docker环境" class="headerlink" title="01、Docker环境"></a>01、Docker环境</h2><p>首先我们需要安装GCC相关的环境：</p>
<pre><code class="shell">yum -y install gcc

yum -y install gcc-c++
</code></pre>
<p>安装Docker需要的依赖软件包：</p>
<pre><code class="shell">yum install -y yum-utils device-mapper-persistent-data lvm2
</code></pre>
<p>设置国内的镜像（提高速度）</p>
<pre><code class="shell">yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
</code></pre>
<p>更新yum软件包索引：</p>
<pre><code class="shell">yum makecache fast
</code></pre>
<p>安装DOCKER CE(注意：Docker分为CE版和EE版，一般我们用CE版就够用了)</p>
<pre><code>yum -y install docker-ce
</code></pre>
<p>启动Docker：</p>
<pre><code>systemctl start docker
</code></pre>
<p>下载回来的Docker版本：:</p>
<pre><code class="shell">docker version
</code></pre>
<p>来一发HelloWorld：</p>
<pre><code class="shell">docker run hello-world
</code></pre>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gwlmnocgsvj31cl0u079x.jpg"></p>
<h2 id="02、Docker-compose环境"><a href="#02、Docker-compose环境" class="headerlink" title="02、Docker compose环境"></a>02、Docker compose环境</h2><blockquote>
<p>Compose 是用于<strong>定义和运行多容器 Docker 应用程序的工具</strong>。通过 Compose，您可以使用 YML 文件来配置应用程序需要的所有服务。然后，使用一个命令，就可以从 YML 文件配置中创建并启动所有服务</p>
</blockquote>
<p>运行以下命令以下载 Docker Compose 的当前稳定版本：</p>
<pre><code class="shell">sudo curl -L &quot;https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)&quot; -o /usr/local/bin/docker-compose
</code></pre>
<p>将可执行权限应用于二进制文件：</p>
<pre><code class="shell">sudo chmod +x /usr/local/bin/docker-compose
</code></pre>
<p>创建软链：</p>
<pre><code class="shell">sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
</code></pre>
<p>测试是否安装成功：</p>
<pre><code class="shell">docker-compose --version
</code></pre>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gwlmuca7iej3148044dgh.jpg"></p>
<h2 id="03、compose-文件"><a href="#03、compose-文件" class="headerlink" title="03、compose 文件"></a>03、compose 文件</h2><p>新建搭建kafka环境的<code>docker-compose.yml</code>文件，内容如下：</p>
<pre><code class="yml">version: &#39;3&#39;services:  zookepper:    image: wurstmeister/zookeeper                    # 原镜像`wurstmeister/zookeeper`    container_name: zookeeper                        # 容器名为&#39;zookeeper&#39;    volumes:                                         # 数据卷挂载路径设置,将本机目录映射到容器目录      - &quot;/etc/localtime:/etc/localtime&quot;    ports:                                           # 映射端口      - &quot;2181:2181&quot;  kafka:    image: wurstmeister/kafka                                # 原镜像`wurstmeister/kafka`    container_name: kafka                                    # 容器名为&#39;kafka&#39;    volumes:                                                 # 数据卷挂载路径设置,将本机目录映射到容器目录      - &quot;/etc/localtime:/etc/localtime&quot;    environment:                                                       # 设置环境变量,相当于docker run命令中的-e      KAFKA_BROKER_ID: 0                                               # 在kafka集群中，每个kafka都有一个BROKER_ID来区分自己      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://ip:9092 # TODO 将kafka的地址端口注册给zookeeper      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092                        # 配置kafka的监听端口      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181                # zookeeper地址      KAFKA_CREATE_TOPICS: &quot;hello_world&quot;    ports:                              # 映射端口      - &quot;9092:9092&quot;    depends_on:                         # 解决容器依赖启动先后问题      - zookepper  kafka-manager:    image: sheepkiller/kafka-manager                         # 原镜像`sheepkiller/kafka-manager`    container_name: kafka-manager                            # 容器名为&#39;kafka-manager&#39;    environment:                        # 设置环境变量,相当于docker run命令中的-e      ZK_HOSTS: zookeeper:2181  #  zookeeper地址      APPLICATION_SECRET: xxxxx      KAFKA_MANAGER_AUTH_ENABLED: &quot;true&quot;  # 开启kafka-manager权限校验      KAFKA_MANAGER_USERNAME: admin       # 登陆账户      KAFKA_MANAGER_PASSWORD: 123456      # 登陆密码    ports:                              # 映射端口      - &quot;9000:9000&quot;    depends_on:                         # 解决容器依赖启动先后问题      - kafka
</code></pre>
<p>文件内**// TODO 中的ip**需要改成自己的，并且如果你用的是云服务器，那需要把端口给打开。</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gwlq503ewej31ps0u042z.jpg"></p>
<h2 id="04、启动kafka"><a href="#04、启动kafka" class="headerlink" title="04、启动kafka"></a>04、启动kafka</h2><p>在存放<code>docker-compose.yml</code>的目录下执行启动命令：</p>
<pre><code class="shell">docker-compose up -d
</code></pre>
<p>可以查看下docker镜像运行的情况：</p>
<pre><code class="shell">docker ps 
</code></pre>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gwlqajny2oj32r80ta7cv.jpg"></p>
<p>进入kafka 的容器：</p>
<pre><code class="shell">docker exec -it kafka sh
</code></pre>
<p>创建一个topic(这里我的topicName就叫austin，你们可以改成自己的)</p>
<pre><code class="shell">$KAFKA_HOME/bin/kafka-topics.sh --create --topic austin --partitions 4 --zookeeper zookeeper:2181 --replication-factor 1 
</code></pre>
<p>查看刚创建的topic信息：</p>
<pre><code class="shell">$KAFKA_HOME/bin/kafka-topics.sh --zookeeper zookeeper:2181 --describe --topic austin
</code></pre>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gwlqkhobg7j32ri0o444b.jpg"></p>
<p>启动一个消费者：</p>
<pre><code class="shell">$KAFKA_HOME/bin/kafka-console-consumer.sh --bootstrap-server kafka:9092 --from-beginning --topic austin
</code></pre>
<p>新增一个窗口，启动一个生产者：</p>
<pre><code class="shell">docker exec -it kafka sh$KAFKA_HOME/bin/kafka-console-producer.sh --topic=austin --broker-list kafka:9092
</code></pre>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gwlqmozxamj31wc066jsb.jpg"></p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gwlqn1r4ybj32ci054ab7.jpg"></p>
<h2 id="05、Java程序验证Kafka"><a href="#05、Java程序验证Kafka" class="headerlink" title="05、Java程序验证Kafka"></a>05、Java程序验证Kafka</h2><p>引入Kafka依赖（SpringBoot有默认的版本，不需要写version）</p>
<pre><code class="xml">&lt;dependency&gt;  &lt;groupId&gt;org.springframework.kafka&lt;/groupId&gt;  &lt;artifactId&gt;spring-kafka&lt;/artifactId&gt;&lt;/dependency&gt;
</code></pre>
<p>定义一个实体类：</p>
<pre><code class="java">@Data@Accessors(chain = true)public class UserLog &#123;    private String username;    private String userid;    private String state;&#125;
</code></pre>
<p>定义生产者（austin是topicName）：</p>
<pre><code class="java">@Componentpublic class UserLogProducer &#123;    @Autowired    private KafkaTemplate kafkaTemplate;    /**     * 发送数据        * @param userid     */    public void sendLog(String userid)&#123;        UserLog userLog = new UserLog();        userLog.setUsername(&quot;jhp&quot;).setUserid(userid).setState(&quot;0&quot;);        System.err.println(&quot;发送用户日志数据:&quot;+userLog);        kafkaTemplate.send(&quot;austin&quot;, JSON.toJSONString(userLog));    &#125;&#125;
</code></pre>
<p>定义消费者：</p>
<pre><code class="java">@Component@Slf4jpublic class UserLogConsumer &#123;    @KafkaListener(topics = &#123;&quot;austin&quot;&#125;,groupId = &quot;austinGroup1&quot;)    public void consumer(ConsumerRecord&lt;?,?&gt; consumerRecord)&#123;        //判断是否为null        Optional&lt;?&gt; kafkaMessage = Optional.ofNullable(consumerRecord.value());        log.info(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; record =&quot; + kafkaMessage);        if(kafkaMessage.isPresent())&#123;            //得到Optional实例中的值            Object message = kafkaMessage.get();            System.err.println(&quot;消费消息:&quot;+message);        &#125;    &#125;&#125;
</code></pre>
<p>定义接口：</p>
<pre><code class="java">@RestControllerpublic class KafkaTestController &#123;    @Autowired    private UserLogProducer userLogProducer;    /**     * test insert     */    @GetMapping(&quot;/kafka/insert&quot;)    public String insert(String userId) &#123;        userLogProducer.sendLog(userId);        return null;    &#125;&#125;
</code></pre>
<p>测试：<code>http://localhost:8080/kafka/insert?userId=3y</code></p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gwlr9voof5j32m005440m.jpg"></p>
<h2 id="06、总结"><a href="#06、总结" class="headerlink" title="06、总结"></a>06、总结</h2><p>搭建环境什么的没什么需要总结的，按着教程一步一步执行应该就完事了？下周会具体实现<code>austin-api</code>和<code>austin-api-impl</code>模块的内容，可以继续关注下。</p>
<p><strong>今天又是被白嫖的一天，哎</strong>😌。</p>
<p>Gitee链接：<a target="_blank" rel="noopener" href="https://gitee.com/zhongfucheng/austin">https://gitee.com/zhongfucheng/austin</a></p>
<p>GitHub链接：<a target="_blank" rel="noopener" href="https://github.com/ZhongFuCheng3y/austin">https://github.com/ZhongFuCheng3y/austin</a></p>

</div>


    <div class="post-guide">
        <div class="item left">
            
        </div>
        <div class="item right">
            
              <a href="/luffy/2021/11/24/12-austin%E9%A1%B9%E7%9B%AE/06.MySQL%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">
                06.MySQL环境搭建
                <i class="fa fa-angle-right" aria-hidden="true"></i>
              </a>
            
        </div>
    </div>




<script>
	
	
</script>
	</div>
	<button id="totop-toggle" class="toggle"><i class="fa fa-angle-double-up" aria-hidden="true"></i></button>
</body>
</html>
